<?php
require('common_view_functions.php');

function without_time($dt_str) {
	$r = explode(' ', $dt_str);
	return $r[0];
}

function add_email($sender_name, $sender_email) {
	return ($sender_email == '') ? htmlspec($sender_name) : '<a href="mailto:' . $sender_email . '">' . htmlspec($sender_name) . '</a>';
}

function get_avatar_name($user_id, $rand = FALSE) {
	$fn = $_SERVER['DOCUMENT_ROOT'] . '/img/avatars/avt_' . $user_id . '_48x48.jpg';
	if(file_exists($fn)) {
		if($rand) {
			return 'avt_' . $user_id . '_48x48.jpg?R=' . rand();
		} else {
			return 'avt_' . $user_id . '_48x48.jpg';
		}
	} else {
		return 'avt_-1_48x48.jpg';
	}
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Blog 用户后台管理 - 悄悄话</title>
<link rel="shortcut icon" href="/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/css/mgmt.css" />
<link rel="stylesheet" type="text/css" href="/css/3rd/jqModal.css" />
</head>
<body id="bodyMsgs">
<div id="wrapper">
	<!-- header -->
	<?php require('common_header.php'); ?>
	<!-- /header -->
	<div id="body">
		<div id="bigger_main">
			<table id="tblPMList" cellspacing="0">
				<caption>悄悄话列表</caption>
				<tr>
					<th>&nbsp;发信人</th>
					<th>悄悄话标题</th>
					<th>发送时间</th>
					<th>操作</th>
				</tr>
				<?php foreach($messages_list as $ml) { ?>
				<tr id="mr_<?php echo($ml->id); ?>"<?php if($ml->read == 0) { ?> class="new"<?php } ?>>
					<td><img alt="" src="/img/avatars/<?php echo(get_avatar_name($ml->from_blogger_id)); ?>" class="msg_avatar" /> <?php echo(add_email($ml->sender_name, $ml->sender_email)); ?></td>
					<td class="ttl"><a href="get_message/<?php echo($ml->id); ?>"><?php echo(htmlspec($ml->title)); ?></a></td>
					<td><?php echo($this->common->NicerTime($ml->sent_time)); ?></td>
					<td class="del"><a title="删除" href="javascript:;" rel="d_<?php echo($ml->id); ?>"><img alt="Delete" border="0" src="<?php echo(base_url() . 'img/delete.png'); ?>" /></a></td>
				</tr>
				<?php } ?>
			</table>
		</div>
		<div class="z"></div>
	</div>
	<!-- footer -->
	<?php require('common_footer.php'); ?>
	<!-- /footer -->
</div>

<!-- JS -->
<script type="text/javascript" src="/js/3rd/jquery.pack.js"></script>
<script type="text/javascript" src="/js/3rd/jqModal.js"></script>
<script type="text/javascript" src="/js/3rd/json2.js"></script>
<script type="text/javascript">
<!--
var g_userSiteRoot = "<?php echo('/' . $blogger_uri); ?>";

function delMsgCallback(rdata) {
	$("#ajaxLoading").hide();
	
	rdata = rdata.split("_");
	if(rdata[0] != "SUCC") {
		alert("Operation failed!");
		return;
	}
	var mid = rdata[1];
	$("#mr_" + mid).fadeOut();
}

$(document).ready(function() {
	$("#tblPMList td a").click(function() {
		var opmid = $(this).attr("rel");
		opmid = opmid.split("_");
		var op = opmid[0];
		var mid = opmid[1];
		if(op == "d") {
			if(confirm("确定要删除这条悄悄话？")) {
				$("#ajaxLoading").show();
				$.post(g_userSiteRoot + "/mgmt/messages", {
					"hidIsPostBack": "ja",
					"operation": "delete",
					"pm_id": mid
				}, delMsgCallback);
			}
		}
	});	
});
// -->
</script>
<!-- /JS -->

<div id="ajaxLoading"><img alt="Loading..." src="<?php echo(base_url() . 'img/ajax_loading.gif'); ?>" border="0" width="24" height="24" /></div>
</body>
</html>
